package com.rs.game.player.content.construction;

import java.util.ArrayList;

import com.rs.game.RegionBuilder;
import com.rs.game.WorldObject;
import com.rs.game.WorldTile;
import com.rs.game.player.content.construction.Furniture.FurnitureObject;
import com.rs.game.player.controlers.Controler;

public class HouseController extends Controler {

	private House house;
    private int[] boundChuncks;
     
    @Override
	public boolean login() {
		player.setNextWorldTile(new WorldTile(HouseLocation.RIMMINGTON.getX(), HouseLocation.RIMMINGTON.getY(), 0));
		return false;
	}
	
	@Override
	public void forceClose() {
		player.setNextWorldTile(new WorldTile(HouseLocation.RIMMINGTON.getX(), HouseLocation.RIMMINGTON.getY(), 0));
	}

	@Override
	public boolean logout() {
		player.setNextWorldTile(new WorldTile(HouseLocation.RIMMINGTON.getX(), HouseLocation.RIMMINGTON.getY(), 0));
		return false;
	}
    
    @Override
    public void start() {
    	player.setHouseController(this);
        house = new House(player);
        if (player.hasBeenToHouse()) {
        	player.setNextWorldTile(new WorldTile(player.getHouseX(), player.getHouseY(), 0));
        	house.constructHouse(player.getBoundChuncks(), player.isBuildMode());
        	house.refresh(player, player.getBoundChuncks());
        } else if (!player.hasBeenToHouse()) {
        	boundChuncks = RegionBuilder.findEmptyChunkBound(8, 8);
        	for (int i = 0; i < boundChuncks.length; i++) {
        		player.setBoundChuncks(boundChuncks);
        	}
            house.constructHouse(boundChuncks, player.isBuildMode());
            player.setNextWorldTile(new WorldTile(boundChuncks[0]*8 + 35, boundChuncks[1]*8 + 35,0));
            player.setHouseX(boundChuncks[0]*8 + 35);
            player.setHouseY(boundChuncks[1]*8 + 35);
            player.setBeenToHouse(true);
            player.setPlace(0);
            house.refresh(player, player.getBoundChuncks());
        }
    }
     
    boolean remove = true;
    /**
     * return process normaly
     */
    
    public boolean processObjectClick5(WorldObject object) {
    	ArrayList<FurnitureObject> furnitures = FurnitureObject.forHotSpotName(object.getDefinitions().name);
    	if (furnitures != null && furnitures.size() > 0) {
    		player.getFurnInterface().showInterface(player, furnitures);
    	} else {
    		player.getPackets().sendGameMessage("BUILD: "+object.getDefinitions().name);
    	}
        return false;
    }
}
